﻿@model RoleMemberViewModel
	<form class="layui-form" asp-controller="Administrator" asp-action="RoleMember" method="post">
		<div class="layui-form-item">
			<label class="layui-form-label">角色名：</label>
			<div class="layui-input-inline layui-input-company">@ViewBag.RoleName</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">成员管理：</label>
			<div class="layui-input-block">
				<div id="ctlMemberList"></div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="btnSubmit">提交</button>
				<button type="button" class="layui-btn layuiadmin-btn-list" onclick="layer_close()">取消</button>
				<input type="hidden" asp-for="RoleID" />
				<input type="hidden" id="hidBelongToRole" name="hidBelongToRole" />
			</div>
		</div>
	</form>
@section scripts{
	<script type="text/javascript">
		layui.use(['form', 'transfer'], function () {
			var transfer = layui.transfer;
			var form = layui.form;
			var leftData = @if (Model != null && Model.MemberByNotRole != null)
				{
					@Html.Raw(@Model.MemberByNotRole.ToJson());
				};
			var rightData = @if (Model != null && Model.MemberByRole != null)
				{
					@Html.Raw(@Model.MemberByRole.ToJson());
				};
			if (leftData == null || leftData.length <= 0) {
				leftData = rightData;
			}
			var selectData = new Array();
			for (i = 0; i < rightData.length; i++) {
				selectData[i] = rightData[i].AdminID;
			}
			transfer.render({
				elem: '#ctlMemberList'
				, title: ['未属于该角色的管理员', '已属于该角色的管理员']
				, data: leftData
				, value: selectData
				, id: "ctlTransfer"
				, parseData: function (res) {
					return {
						"value": res.AdminID //数据值
						, "title": res.AdminName //数据标题
						, "disabled": false  //是否禁用
						, "checked": false //是否选中
					}
				}
			});
			//监听提交
			form.on('submit(btnSubmit)', function (data) {
				//获得右侧数据
				var adminId = "";
				var getData = transfer.getData('ctlTransfer');
				for (i = 0; i < getData.length; i++){
					if (adminId == "") {
						adminId = getData[i].value;
					}
					else {
						adminId += "," + getData[i].value;
					}
				}
				$("#hidBelongToRole").val(adminId);
			});

		});
	</script>
}